﻿using Library.Common.Model;
using Library.Core.Domain.Repository;
using Microsoft.AspNetCore.Mvc;
using Synthesize.BaseSet.ServiceInterface.Dtos.Authority.Post;
using Synthesize.BaseSet.ServiceInterface.Query.Authority;
using Synthesize.BaseSet.ServiceInterface.UseCase.Authority;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SMS.WebApi.Areas.BaseSet.Controllers
{
    /// <summary>
    /// 岗位
    /// </summary>

    public class PostController : BaseSetBaseController
    {

        private readonly IPostQueryService _postQueryService;
        private readonly IPostService _postService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="postQueryService"></param>
        /// <param name="postService"></param>
        public PostController(IPostQueryService postQueryService
            , IPostService postService)
        {
            _postQueryService = postQueryService;
            _postService = postService;
        }

        /// <summary>
        /// 获取岗位分页列表信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<BaseApiResult<PageData<GetPostListOutput>>> GetPostPageList([FromQuery]GetPostListInput input)
        {
            return _postQueryService.GetPostPageList(input); 
        }

        /// <summary>
        /// 获取所有岗位列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<BaseApiResult<List<GetPostListOutput>>> GetAllList()
        {
            return await _postQueryService.GetAllList();
        }

        /// <summary>
        /// 创建岗位
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseApiResult<bool>> Create(CreatePostInput input)
        {
            var res = await _postService.Create(input);
            return res;
        }

        /// <summary>
        ///  禁用/启用岗位
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<BaseApiResult<bool>> ForbidOrEnable(ForbidOrEnableInput input)
        {
            return _postService.ForbidOrEnable(input);
        }

        /// <summary>
        /// 更新岗位
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> Update(UpdatePostInput input)
        {
            var res = await _postService.Update(input);
            return res;
        }

        /// <summary>
        /// 更新岗位-用户信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> UpdatePostUser(UpdatePostUserInput input)
        {
            var res = await _postService.UpdatePostUser(input);
            return res;
        }
        

        /// <summary>
        /// 删除岗位
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<BaseApiResult<bool>> DeleteById(SingleDeleteInput input)
        {
            var res = await _postService.DeleteById(input);
            return res;
        }

        /// <summary>
        /// 删除指定的用户-岗位关系
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<BaseApiResult<bool>> DeleteUserPost(DeleteUserPostInput input)
        {
            var res = await _postService.DeleteUserPost(input);
            return res;
        }
    }
}
